package android.slc.appbase.utils;


import android.slc.appbase.R;

import com.blankj.utilcode.util.SizeUtils;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

public class GlideUtils {
    private static RequestOptions headRequestOptions;
    private static RequestOptions centerCropOptions;
    private static RequestOptions photoReviewOptions;
    private static BitmapTransformation roundedCornersTransformation;
    private static BitmapTransformation centerCropTransformation;

    /**
     * 获取用户头像的RequestOptions
     *
     * @return
     */
    public static synchronized RequestOptions getHeadRequestOptions() {
        if (headRequestOptions == null) {
            headRequestOptions = new RequestOptions()
                    .placeholder(R.drawable.app_ic_def_user_head)
                    .error(R.drawable.app_ic_def_user_head);
        }
        return headRequestOptions;
    }

    public static synchronized RequestOptions getCenterCropOptions() {
        if (centerCropOptions == null) {
            centerCropOptions = new RequestOptions()
                    .centerCrop()
                    .placeholder(R.drawable.slc_mp_ic_loading_anim)                //加载成功之前占位图
                    .error(R.drawable.slc_mp_ic_loading_failure);
        }
        return centerCropOptions;
    }

    public static synchronized RequestOptions getPhotoReviewOptions() {
        if (photoReviewOptions == null) {
            photoReviewOptions = new RequestOptions()
                    .placeholder(R.drawable.slc_mp_ic_loading_anim)                //加载成功之前占位图
                    .error(R.drawable.slc_mp_ic_loading_failure)
                    .skipMemoryCache(false);
        }
        return photoReviewOptions;
    }

    public static synchronized BitmapTransformation getRoundedCornersTransformation4() {
        if (roundedCornersTransformation == null) {
            roundedCornersTransformation = new RoundedCorners(SizeUtils.dp2px(4));
        }
        return roundedCornersTransformation;
    }

    public static synchronized BitmapTransformation getCenterCropTransformation() {
        if (centerCropTransformation == null) {
            centerCropTransformation = new CenterCrop();
        }
        return centerCropTransformation;
    }
}
